/*
 * @Author: 刘庆州 
 * @Date: 2022-01-08 17:32:49 
 * @Last Modified by: 刘庆州
 * @Last Modified time: 2022-03-15 15:15:45
 */


import StorageUtil from "../utils/StorageUtil";
export default class UserManager {

  static async setUserInfo(data) {

    // {"InvOrg": 8010, "UserCode": "admin", "UserId": 1, "UserName": "admin"}

    console.log("setUserInfo:" , data)
    await StorageUtil.set('userInfo', data);

    console.log("setUserInfo end:" )
  }


  static async getUserInfo() {


    var userInfo = null
    // {"InvOrg": 8010, "UserCode": "admin", "UserId": 1, "UserName": "admin"}
    await StorageUtil.get('userInfo', (error, object) => {

      console.log("getUserInfo:" ,object )
      userInfo  = object
      
    })


    return userInfo
  }


  static async setTicket(data) {

    console.log("set ticket call===", data)
    await StorageUtil.set('ticket', data);
    console.log("set ticket end===", data)
  }


  static async getTicket(){

   
    var ticket = ''

    await StorageUtil.get('ticket', (error, object) => {

      console.log("ticket is" + object)
      if (!error && object) {
        ticket = object;
        
      }
    })

    return ticket

  }

  static async setLongTicket(data) {
    await StorageUtil.set('longTicket', data);
  }


  static async getLongTicket(){

    let longTicket = ''

    await StorageUtil.get('longTicket', (error, object) => {

      
      longTicket = object
    })

    return longTicket

  }


  static async setCategory(data) {

    // {"Id": 3, "Name": "移动端", "Sort": 1}
    console.log("setCategory:" , data)
    await StorageUtil.set('category', data);

    console.log("setCategory end:" )
  }

  static async getCategory() {


    var category = null
    // {"InvOrg": 8010, "UserCode": "admin", "UserId": 1, "UserName": "admin"}
    await StorageUtil.get('category', (error, object) => {

      console.log("getCategory:" ,object )
      category  = object
      
    })


    return category
  }


  /**
   * 
   * @param {设置ip地址} data 
   */
  static async setIpAddress(data) {

    await StorageUtil.set('ipAddress', data);
  }


  static async getIpAddress(){

   
    var ip = ''

    await StorageUtil.get('ipAddress', (error, object) => {

      console.log("ip is" + object)
      if (!error && object) {
        ip = object;
        
      }
    })

    return ip

  }



  static async setPort(data) {

    await StorageUtil.set('port', data);
  }


  static async getPort(){

   
    var port = ''

    await StorageUtil.get('port', (error, object) => {

      console.log("port is" + object)
      if (!error && object) {
        port = object;
        
      }
    })

    return port

  }

}
